﻿using System.Collections.ObjectModel;

using TrivialPurfuit.Data;

namespace TrivialPurfuit.Business
{
    class QuestionCollection : BindableObject
    {
        /// <summary>
        /// The collection of questions.
        /// </summary>
        private static ObservableCollection<QuestionCard> _Questions;
        public static ObservableCollection<QuestionCard> Questions
        {
            get
            {
                if (_Questions == null)
                    buildTheQuestionsCollection();

                return _Questions;
            }
        }

        private static void buildTheQuestionsCollection()
        {
            _Questions = new ObservableCollection<QuestionCard>();

            foreach (TPDataSet.QuestionRow qRow in QuestionData.Instance.Question)
                _Questions.Add(new QuestionCard(qRow));
        }

        /// <summary>
        /// The collection of catagories the questions can be.
        /// </summary>
        private static ObservableCollection<QuestionCategory> _Categories;
        public static ObservableCollection<QuestionCategory> Categories
        {
            get
            {
                if (_Categories == null)
                    buildTheCatagoriesCollection();

                return _Categories;

            }
        }

        private static void buildTheCatagoriesCollection()
        {
            _Categories = new ObservableCollection<QuestionCategory>();

            foreach (TPDataSet.CategoryRow cRow in QuestionData.Instance.Catagory)
                _Categories.Add(new QuestionCategory(cRow));
        }

        /// <summary>
        /// Saves the changes to the questions and catagories.
        /// </summary>
        public static void saveChanges()
        {
            QuestionData.Instance.saveData();
        }

    }
}
